package model.entity.product;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "Category")
public class Category {

	private int categoryId;
	private Category category;
	private String name;
	private String image;
	private String description;
	private List<Category> categories = new ArrayList<Category>(0);
	private List<Product> products = new ArrayList<Product>(0);

	public Category() {
	}

	public Category(String name) {
		this.name = name;
	}

	public Category(Category category, String name,
			String image, String description, List<Category> categories,
			List<Product> products) {
		this.category = category;
		this.name = name;
		this.image = image;
		this.description = description;
		this.categories = categories;
		this.products = products;
	}

	@Id
	@GeneratedValue(generator = "Category_ID_Gen", strategy = GenerationType.IDENTITY)
	@SequenceGenerator(name = "Category_ID_Gen", sequenceName = "Category_SEQ_ID")
	@Column(name = "CategoryID", unique = true, nullable = false)
	public int getCategoryId() {
		return this.categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ParentCategoryID")
	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@Column(name = "Name", nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "Image")
	public String getImage() {
		return this.image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	@Column(name = "Description")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
	public List<Category> getCategories() {
		return this.categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "category")
	public List<Product> getProducts() {
		return this.products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

}
